package dk.dtu.android.transport.gps;

import dk.dtu.android.transport.TransportAPI;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.IBinder;
import android.util.Log;

public class GPSService extends Service {

	public static LocationManager mLocMan;
	public static LocationListener mLocList = new MyLocationListener();
	
	public void onCreate() {
		super.onCreate();
        try
        {
        	Log.d("TRANSPORT", "Starting GPSService!");
			mLocMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);		
			mLocMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mLocList);
			TransportAPI.sendPendingRequests();
        }
        catch (Exception e)
        {
        	
        }
        finally
        {
        	//GPSAlarmReceiver.updateAlarm();
        	stopSelf(1);
        }
	}

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}
	
	public void onDestroy() {
		Log.d("TRANSPORT", "Stopping GPSService!");
	}
	
	public static void serviceStarter(Context context)
	{
		Intent serviceIntent = new Intent(context, GPSService.class);
		context.startService(serviceIntent);
	}
	
}